package com.zhu.char08

/**
 *
 * @version 1.0
 * @author study
 * @date 2020/9/5 22:54
 *
 */
object Scala_TestMatch {

  def main(args: Array[String]): Unit = {
    var a: Int = 1
    var b: Int = 2

    var opStr = "+"

    //模式匹配有返回值
    //模式匹配 没有break关键字，case分支结束后，直接跳出
    var res = opStr match {
      case "+" => a + b
      case "-" => a - b
      case "*" => a * b
      case "/" => a / b
      case _ => "运算符不合法"
    }

    println(res)

    //模式守卫
    def abs(num: Int) = {
      num match {
        case i: Int if i >= 0 => i
        case j: Int if j < 0 => -j
      }
    }


  }
}
